package com.uprr.netcontrol.starmap.rest.converter;

import java.io.Reader;
import java.io.StringReader;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

import com.up.www.schemas.netcontrol.common.starmap.nc_du_deployment_descriptor_1_0.DeploymentUnit;

/*
 * This class is responsible to unmarshall string xml to schema type.
 */
public class RequestConverter {

  private static final String NAMESPACE = "com.up.www.schemas.starmap.netcontrol.common.nc_du_deployment_descriptor_1_0";

  public static  DeploymentUnit convert(final Reader reader) throws JAXBException {
      if(reader ==null) throw new JAXBException("Stream is not available");
      JAXBContext context = JAXBContext.newInstance(NAMESPACE);
      Unmarshaller unmarshaller = context.createUnmarshaller();
      // return ((JAXBElement<DistributionPackage>) unmarshaller.unmarshal(new
      // StringReader(xml))).getValue();
      DeploymentUnit schemaType = (DeploymentUnit) unmarshaller.unmarshal(reader);
      return schemaType;
   
    
  }
}
